# -*- coding: utf-8 -*-

import sys
import ConfigParser
import MySQLdb as mdb
import random
import sys,os
import unittest

class SchemaTest(unittest.TestCase):
    '''
    unit tests to test db schema
    '''


    def setUp(self):
        self.config = ConfigParser.ConfigParser()
        self.config.readfp(open(os.path.join(sys.path[0],"app.cfg")))

	self.instance = self.config.get("mysqld","instance")
        self.user = self.config.get("mysqld","user")
        self.password = self.config.get("mysqld","password")
        self.database = self.config.get("mysqld","database")

    def test_LookupSproc(self):
       	self.conn = mdb.connect(self.instance,self.user,self.password,self.database)
	self.cursor = self.conn.cursor()
        hash = random.getrandbits(128)
        self.cursor.execute("select first_occurrence from \
                                    partner_gate_db.partner_gate_lookup \
                                    where partner_id = %s and \
                                    tracking_url = CAST(UNHEX(%s) AS BINARY(16)) \
                                    order by first_occurrence desc LIMIT 1; " % (hash,5005))	
        myreturn = self.cursor.fetchone()
        self.assertEqual(type(myreturn[0]), long)
 
    
    def tearDown(self):
        self.cursor.close()
        self.conn.close()
            
